<template>
<div ref="warpper">
  <div class="content">
    <slot></slot>
  </div>
</div>


</template>
<script>
import PullUp from '@better-scroll/pull-up'
import BScroll from '@better-scroll/core'
BScroll.use(PullUp)

export default {
  name: "BScroll",
  data() {
    return {
      scroll: null,

    }
  },
  mounted() {
     this.scroll = new BScroll(this.$refs.warpper, {
       probeType:3,
       disable: false,
       movable: true,
       zoom: true,
       click:true,
       scrollY: true,
       bounceTime: 500,
       pullUpLoad: true,


    });
    // console.log(this.scroll);
   // 获取当前滚动到的位置
   this.scroll.on('scroll', (position) =>{
     // console.log(position);
     this.$emit('contentposition',position)
    });

    //上拉加载更多
    this.scroll.on('pullingUp', () =>{
     this.$emit('pullingup')
      //设置多次，没这个 只能下拉一次
      this.scroll.finishPullUp()
    })
    // console.log(this.scroll);
  },
  methods:{
    scrollTo (itemx,itemy,time) {
      this.scroll &&  this.scroll.scrollTo(0,itemy,time);
      },
    refresh () {
      // console.log('收到了');
      this.scroll && this.scroll.refresh();  //解决refresh中的问题 ，会出现refresh未定义的错误，原因是scroll组件还没有挂载出来就调用了他的方法
    },

  }

}
</script>

<style scoped>

.content{
}
</style>